import Vue from 'vue'
import axios from 'axios'
import qs from 'qs'
import {Message, Loading} from 'element-ui'
// 响应时间
axios.defaults.timeout = 180000;
// 配置cookie
// axios.defaults.withCredentials = true
// 配置请求头
// 静态资源
Vue.prototype.$static = '';

// 配置接口地址
// axios.defaults.baseURL = 'http://localhost:9000/dbfg/';
// axios.defaults.baseURL = 'http://192.168.1.5:9000/dbfg/';

// 发送
axios.interceptors.request.use(config => {

    return config
}, error => {
    return Promise.reject(error)
})

// 接收
axios.interceptors.response.use(response => {
    // 关闭loading
    return response
}, error => {
    return Promise.reject(error)
})

// 发送请求
export function post(url, params) {
    return new Promise((resolve, reject) => {
        axios
        ({
            method: "POST",
            url: url,
            data: params,
            headers: {
                'Content-Type': 'application/text'
            }
        })
            .then(
                res => {
                    resolve(res)
                },
                err => {
                    reject(err)
                }
            )
            .catch(err => {
                reject(err)
            })
    })
}

export function get(url, params) {
    return new Promise((resolve, reject) => {
        axios
            .get(url, {
                params: params
            })
            .then(res => {
                resolve(res)
            })
            .catch(err => {
                reject(err)
            })
    })
}